﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class Admin_shgl : System.Web.UI.Page
{
    DataClassesDataContext db1 = new DataClassesDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            MultiView1.SetActiveView(View1);
            BindData1();
            Button1.ForeColor = Color.Red;
            string IP = Request.ServerVariables.Get("Remote_Addr").ToString();
            string nowtime = DateTime.Now.ToString();
            DateTime nowtime1 = Convert.ToDateTime(nowtime);
            int nowusername = Convert.ToInt32(Session["username"]);
            var newrizhi = new rizhi
            {
                userName = nowusername,
                time = nowtime1,
                ip = IP,
                caozuo = "进入审核管理"
            };
            db1.rizhi.InsertOnSubmit(newrizhi);
            db1.SubmitChanges();
        }
    }
    protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lbl = (Label)e.Row.Cells[0].FindControl("Label2");
            lbl.Text = (GridView2.PageIndex * GridView2.PageSize + e.Row.RowIndex + 1).ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
        BindData1();
        Button1.ForeColor = Color.Red;
        Button2.ForeColor = Color.White;
        Button3.ForeColor = Color.White;
        Button4.ForeColor = Color.White;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View2);
        BindData2();
        Button1.ForeColor = Color.White;
        Button2.ForeColor = Color.Red;
        Button3.ForeColor = Color.White;
        Button4.ForeColor = Color.White;
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View3);
        BindData3();
        Button1.ForeColor = Color.White;
        Button2.ForeColor = Color.White;
        Button3.ForeColor = Color.Red;
        Button4.ForeColor = Color.White;
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View4);
        BindData4();
        Button1.ForeColor = Color.White;
        Button2.ForeColor = Color.White;
        Button3.ForeColor = Color.White;
        Button4.ForeColor = Color.Red;
    }
    private void BindData1()
    {
        var result = (from p in db1.proc_GetStuInfo()
                      where p.proflag == 2 && (p.wbh.Contains(TextBox1.Text) || p.sname.Contains(TextBox1.Text) || p.proName.Contains(TextBox1.Text))
                      select p).ToList();
        GridView2.DataSource=result;
        GridView2.DataBind();
    }
    
     private void BindData2()
        {
            var resultYear = (from p in db1.proc_GetBkgxNowYear()
                              select p).ToList().First();
            string ZcYear = resultYear.dYear;
            var Haveresult = (from p in db1.proc_GetStuInfo()
                              where p.bkyear == ZcYear && p.proflag > 2 && p.proflag!= 4 && p.zKZflag != 1 && (p.wbh.Contains(TextBox2.Text) || p.sname.Contains(TextBox2.Text) ||p.proName.Contains(TextBox2.Text))
                              select p).ToList();
         GridView5.DataSource=Haveresult;
        GridView5.DataBind();
     }
     private void BindData3()
        {
            var resultYear = (from p in db1.proc_GetBkgxNowYear()
                              select p).ToList().First();
            string ZcYear = resultYear.dYear;
            var Haveresult = (from p in db1.proc_GetStuInfo()
                              where p.bkyear == ZcYear && p.proflag > 2 && p.proflag != 4 && p.zKZflag==1 && (p.wbh.Contains(TextBox3.Text) || p.sname.Contains(TextBox3.Text) || p.proName.Contains(TextBox3.Text))
                              select p).ToList();
         GridView3.DataSource=Haveresult;
        GridView3.DataBind();
     }
     private void BindData4()
    {
     var result = (from p in db1.proc_GetStuInfo()
                          where p.proflag == 4 && (p.wbh.Contains(TextBox4.Text) || p.sname.Contains(TextBox4.Text) || p.proName.Contains(TextBox4.Text))
                          select p).ToList();
         GridView4.DataSource=result;
        GridView4.DataBind();
     }
    protected void GridView5_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        BindData1();
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        BindData2();
    }
    protected void Button7_Click(object sender, EventArgs e)
    {
        BindData3();
    }
    protected void Button8_Click(object sender, EventArgs e)
    {
        BindData4();
    }
    protected void GridView3_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 得到该控件
        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (e.NewPageIndex == -3)
        {
            //点击了Go按钮
            TextBox txtNewPageIndex = null;

            //GridView较DataGrid提供了更多的API，获取分页块可以使用BottomPagerRow 或者TopPagerRow，当然还增加了HeaderRow和FooterRow
            GridViewRow pagerRow = theGrid.BottomPagerRow;

            if (pagerRow != null)
            {
                //得到text控件
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
            }
            if (txtNewPageIndex != null)
            {
                //得到索引
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
            }
        }
        else
        {
            //点击了其他的按钮
            newPageIndex = e.NewPageIndex;
        }
        //防止新索引溢出
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

        //得到新的值
        theGrid.PageIndex = newPageIndex;
        BindData3();
    }
    protected void GridView4_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 得到该控件
        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (e.NewPageIndex == -3)
        {
            //点击了Go按钮
            TextBox txtNewPageIndex = null;

            //GridView较DataGrid提供了更多的API，获取分页块可以使用BottomPagerRow 或者TopPagerRow，当然还增加了HeaderRow和FooterRow
            GridViewRow pagerRow = theGrid.BottomPagerRow;

            if (pagerRow != null)
            {
                //得到text控件
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
            }
            if (txtNewPageIndex != null)
            {
                //得到索引
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
            }
        }
        else
        {
            //点击了其他的按钮
            newPageIndex = e.NewPageIndex;
        }
        //防止新索引溢出
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

        //得到新的值
        theGrid.PageIndex = newPageIndex;
        BindData4();
    }
    protected void GridView2_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 得到该控件
        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (e.NewPageIndex == -3)
        {
            //点击了Go按钮
            TextBox txtNewPageIndex = null;

            //GridView较DataGrid提供了更多的API，获取分页块可以使用BottomPagerRow 或者TopPagerRow，当然还增加了HeaderRow和FooterRow
            GridViewRow pagerRow = theGrid.BottomPagerRow;

            if (pagerRow != null)
            {
                //得到text控件
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
            }
            if (txtNewPageIndex != null)
            {
                //得到索引
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
            }
        }
        else
        {
            //点击了其他的按钮
            newPageIndex = e.NewPageIndex;
        }
        //防止新索引溢出
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

        //得到新的值
        theGrid.PageIndex = newPageIndex;
        BindData1();
    }
    protected void GridView5_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        // 得到该控件
        GridView theGrid = sender as GridView;
        int newPageIndex = 0;
        if (e.NewPageIndex == -3)
        {
            //点击了Go按钮
            TextBox txtNewPageIndex = null;

            //GridView较DataGrid提供了更多的API，获取分页块可以使用BottomPagerRow 或者TopPagerRow，当然还增加了HeaderRow和FooterRow
            GridViewRow pagerRow = theGrid.BottomPagerRow;

            if (pagerRow != null)
            {
                //得到text控件
                txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
            }
            if (txtNewPageIndex != null)
            {
                //得到索引
                newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
            }
        }
        else
        {
            //点击了其他的按钮
            newPageIndex = e.NewPageIndex;
        }
        //防止新索引溢出
        newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
        newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;

        //得到新的值
        theGrid.PageIndex = newPageIndex;
        BindData2();
    }
}